/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package fantasy;

/**
 *
 * @author shack
 */

import javax.mail.*;  
import javax.mail.internet.*;  
import java.util.*;  
  
public class SendMail {  
  
         String username=null;  
         String password=null;  
  
        /** Creates a new instance of SendMail */  
        public SendMail() {  
        }  
  
      // public void postMail( String recipients[ ], String subject, String message, String from, String pwd) throws MessagingException  
        public void postMail(String receptor) //throws MessagingException  
        {  
            String recipients[] = {receptor};
                 boolean debug = false;  
  
                 //Set the host smtp address  
                 Properties props = new Properties();  
  
                 //props.put("mail.smtp.host", "smtp.live.com");  
  
                 String host="smtp.gmail.com";  
                 props.put("mail.smtps.auth", "true");  
  
                 // Authenticator a1= new PopupAuthenticator();  
  
                 // create some properties and get the default Session  
                 Session session = Session.getDefaultInstance(props, null);  
                 session.setDebug(debug);  
  
                 // create a message  
                 Message msg = new MimeMessage(session);  
  
                // set the from and to address  
                //InternetAddress addressFrom = new InternetAddress(from);  
                //msg.setFrom(addressFrom);  
  try{
                InternetAddress[] addressTo = new InternetAddress[recipients.length];   
                for (int i = 0; i < recipients.length; i++)  
                {  
                         addressTo[i] = new InternetAddress(recipients[i]);  
                }  
                msg.setRecipients(Message.RecipientType.TO, addressTo);  
  
                // Setting the Subject and Content Type  
                msg.setSubject("Registro Fantasy Football");  
                msg.setContent("Saludos "+receptor+", para activar su cuenta ingresar a la siguiente pagina http://localhost:8084/Fantasy/PRINCIPAL/redirect.jsp?correo="+receptor, "text/plain");  
  
               //msg.setText(message);  
               //Transport.send(msg);   
  
               username = "fantasyfootballayd2@gmail.com";  
               password = "fantasyfootball";
  
               Transport t = session.getTransport("smtps");  //} catch(Exception e){ e.printStackTrace();}
              // try {  
                           t.connect(host, username, password);  
                           //t.connect(host, username);  
                           t.sendMessage(msg, msg.getAllRecipients());  
              }   
               catch(Exception ex){  
                           //System.out.println(ex);  
                   ex.printStackTrace();
              }  
               /*finally {  
                           t.close();  
               } */
  
        }  
  
}   